package com.zhkj.txg.module.member.model

import com.zhkj.lib.http.BaseManager
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.ResponseSubscribeListener
import com.zhkj.lib.http.SubscribeListener
import com.zhkj.txg.module.member.entity.*
import com.zhkj.txg.module.mine.entity.UserCenterResponse
import com.zhkj.txg.module.order.entity.OrderPayResponse
import io.reactivex.disposables.Disposable

class MemberManager : BaseManager<MemberApi>(MemberApi::class.java) {

    /**
     * 获取会员卡信息
     */
    fun memberCard(
        token: String,
        listener: SubscribeListener<MemberCardResponse>
    ): Disposable {
        val memberCard = apiService.memberCard(token)
        return subscribe(memberCard, ResponseSubscribeListener(listener))
    }

    /**
     * 会员商品列表
     */
    fun memberProductList(
        token: String, page: Int, rows: Int,
        listener: SubscribeListener<MemberProductListResponse>
    ): Disposable {
        val productList = apiService.memberProductList(token, page, rows)
        return subscribe(productList, ResponseSubscribeListener(listener))
    }

    /**
     * 获取会员商品详情
     */
    fun memberProduct(
        token: String, goodsId: Long,
        listener: SubscribeListener<MemberProductResponse>
    ): Disposable {
        val memberProduct = apiService.memberProduct(token, goodsId)
        return subscribe(memberProduct, ResponseSubscribeListener(listener))
    }

    /**
     * 会员支付接口
     */
    fun memberOrderPay(
        token: String, goodsId: Long, goodsNum: Int, specId: Long, addressId: Long, payType: String, code: String,
        listener: SubscribeListener<OrderPayResponse>
    ): Disposable {
        val memberOrderPay = apiService.memberOrderPay(token, goodsId, goodsNum, specId, addressId, payType, code)
        return subscribe(memberOrderPay, ResponseSubscribeListener(listener))
    }

    /**
     * 获取默认地址
     */
    fun defaultAddress(token: String, listener: SubscribeListener<DefaultAddressResponse>): Disposable {
        val defaultAddress = apiService.getDefaultAddress(token)
        return subscribe(defaultAddress, ResponseSubscribeListener(listener))
    }

    /**
     * 我的邀请人列表
     */
    fun inviteList(
        token: String, page: Int, rows: Int, type: Int,
        listener: SubscribeListener<InviteResponse>
    ): Disposable {
        val inviteList = apiService.inviteList(token, page, rows, type)
        return subscribe(inviteList, ResponseSubscribeListener(listener))
    }

    /**
     * 会员订单明细列表
     */
    fun rebateLog(
        token: String, page: Int, rows: Int, type: Int, time: String,
        listener: SubscribeListener<RebateLogResponse>
    ): Disposable {
        val inviteList = apiService.rebateLog(token, page, rows, type, time)
        return subscribe(inviteList, ResponseSubscribeListener(listener))
    }

    /**
     * 收益统计
     */
    fun rebateStatistics(token: String, listener: SubscribeListener<RebateStatisticsResponse>): Disposable {
        val rebateStatistics = apiService.rebateStatistics(token)
        return subscribe(rebateStatistics, ResponseSubscribeListener(listener))
    }

    /**
     * 会员累计收益
     */
    fun totalIncome(
        token: String,
        listener: SubscribeListener<MemberIncomeResponse>
    ): Disposable {
        val totalMemberIncome = apiService.totalMemberIncome(token)
        return subscribe(totalMemberIncome, ResponseSubscribeListener(listener))
    }

    /**
     * 获取会员中心数据
     */
    fun rewardCenter(token: String, listener: SubscribeListener<RewardCenterResponse>): Disposable {
        val rewardCenter = apiService.rewardCenter(token)
        return subscribe(rewardCenter, ResponseSubscribeListener(listener))
    }

    /**
     * 获取日历
     */
    fun memberCalender(token: String, date: String, listener: SubscribeListener<MemberCalendarResponse>): Disposable {
        val memberCalender = apiService.memberCalender(token, date)
        return subscribe(memberCalender, ResponseSubscribeListener(listener))
    }

    /**
     * 获取订单详情
     */
    fun memberOrderList(
        token: String,
        page: Int,
        numb: Int,
        listener: SubscribeListener<MemberOrderResponse>
    ): Disposable {
        val memberOrderList = apiService.memberOrderList(token, page, numb)
        return subscribe(memberOrderList, ResponseSubscribeListener(listener))
    }

    /**
     * 会员订单详情
     */
    fun memberOrderDetail(
        token: String,
        orderId: Long,
        listener: SubscribeListener<MemberOrderDetailResponse>
    ): Disposable {
        val memberOrderDetail = apiService.memberOrderDetail(token, orderId)
        return subscribe(memberOrderDetail, ResponseSubscribeListener(listener))
    }

    /**
     * 会员确认收货
     */
    fun memberReceive(
        token: String,
        orderId: Long,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val memberReceive = apiService.memberReceive(token, orderId)
        return subscribe(memberReceive, ResponseSubscribeListener(listener))
    }

    /**
     * 校验邀请码
     */
    fun checkCode(token: String, code: String, listener: SubscribeListener<CheckResultResponse>): Disposable {
        val checkCode = apiService.checkCode(token, code)
        return subscribe(checkCode, ResponseSubscribeListener(listener))
    }

    /**
     * 获取用户数据
     */
    fun userCenter(
        token: String,
        listener: SubscribeListener<UserCenterResponse>
    ): Disposable {
        val userCenter = apiService.userCenter(token)
        return subscribe(userCenter, ResponseSubscribeListener(listener))
    }


}